﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MusicService
{
    public partial class MusicService:ITrackSingerService
    {
        public bool addTrackSinger(string singerID, string trackID)
        {
            bool flag = false;
            TrackSinger trackSinger = new TrackSinger();
            try
            {
                trackSinger.SingerID = singerID;
                trackSinger.TrackID = trackID;
                dc.TrackSingers.InsertOnSubmit(trackSinger);
                dc.SubmitChanges();
                flag = true;
            }
            catch (Exception)
            {

            }
            return flag;
        }

        public bool removeTrackSinger(string singerID, string trackID)
        {
            bool flag = false;
            try
            {
                TrackSinger trackSinger = dc.TrackSingers.Single(tmp => tmp.SingerID.Equals(singerID) &&
                    tmp.TrackID.Equals(trackID));
                if (trackSinger != null)
                {
                    dc.TrackSingers.DeleteOnSubmit(trackSinger);
                    dc.SubmitChanges();
                    flag = true;
                }
            }
            catch (Exception)
            {

            }
            return flag;
        }

        public bool updateTrackSinger(string singerID, string trackID)
        {
            bool flag = false;
            try
            {
                TrackSinger trackSinger = dc.TrackSingers.Single(tmp => tmp.SingerID.Equals(singerID) &&
                    tmp.TrackID.Equals(trackID));
                if (trackSinger != null)
                {
                    trackSinger.SingerID = singerID;
                    trackSinger.TrackID = trackID;
                    dc.SubmitChanges();
                    flag = true;
                }
            }
            catch (Exception)
            {

            }
            return flag;
        }

        public List<TrackSinger> getAllTrackSinger()
        {
            var list = from ts in dc.TrackSingers select ts;
            return list.ToList();
        }

        public TrackSinger getTrackSinger(string singerID, string trackID)
        {
            TrackSinger trackSinger = dc.TrackSingers.Single(tmp => tmp.SingerID.Equals(singerID) &&
                    tmp.TrackID.Equals(trackID));
            return trackSinger;
        }
    }
}